#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 510;

int n,m,k,d[N];
struct thing { int id,x;} t[N];
bool operator < (thing a,thing b) { return a.x < b.x;}

namespace sub1 {
	void solve(int n,int m) {
		for(int i = 1;i <= m;i++) {
			sort(t + 1,t + n + 1);
			if(t[1].x >= k) t[1].x -= k,printf("%d %d\n",t[1].id,k);
			else printf("%d %d %d %d\n",t[1].id,t[1].x,t[n].id,k - t[1].x),t[n].x -= k - t[1].x,t[1].x = 0;
			if(t[1].x == 0) swap(t[1],t[n]),n--;
		}
	}
}

namespace sub2 {
	const int B = 25e5 + 10;
	bitset <B << 1> f[N];
	bool vis[N];
	void dfs(int p,int t) {
		if(!p) return;
		if(f[p - 1][t + B]) return dfs(p - 1,t);
		else vis[p] = 1, dfs(p - 1,t - (k - d[p]));
	}
	void solve() {
		f[0][B] = 1; bool tag = 0; memset(vis,0,sizeof vis);
		for(int i = 1;i <= n;i++) {
			int sz = k - d[i];
			if(sz > 0) f[i] = f[i - 1] | (f[i - 1] << sz);
			else f[i] = f[i - 1] | (f[i - 1] >> (-sz));
			if(f[i][B + k]) { dfs(i,k); tag = 1; break;}
		}
		if(tag == 0) return puts("-1"),void();
		int cnt = 0;
		for(int i = 1;i <= n;i++) if(vis[i]) t[++cnt] = (thing) {i,d[i]},cerr << i << " " << d[i] << " | "; cerr << endl;
		sub1 :: solve(cnt,cnt - 1);
		cnt = 0; for(int i = 1;i <= n;i++) if(!vis[i]) t[++cnt] = (thing) {i,d[i]};
		sub1 :: solve(cnt,cnt - 1);
	}
}

int main() {
#ifndef ONLINE_JUDGE
	//	freopen("1.in","r",stdin);
#endif
	for(int T = in;T;T--) {
		n = in,m = in,k = in; for(int i = 1;i <= n;i++) d[i] = in;
		if(m >= n - 1) {
			for(int i = 1;i <= n;i++) t[i].id = i , t[i].x = d[i];
			sub1 :: solve(n,m);
		} else sub2 :: solve();
	}
	return 0;
}
